<include file="Public:header" /> 
<style type="text/css">
.cart{width:1180px;height:100%;margin:0 auto;margin-top:20px;border:1px solid #DDDDDD;padding:10px;background-color:#fffee6;}
.cart img{border:0px;}
table{background-color:#fff;font-size:13px;border-collapse: collapse;border:1px solid #DDDDDD;margin:0 auto;margin-top:10px;}
table a{color:#005EA7;text-decoration:none}
td span{color:#FF0000;}

.total{margin-top:10px;}
.total span{display:block;float:left;}

.toorder{width:1200px;height:40px;margin:0 auto;margin-top:10px;}
.toorder span{display:block;float:right;}
</style>

<div class="cart">
<div class="good">
<span>已放入购物车的商品:</span>
<table width="100%" border="1" cellpadding="5">
<tr align="center" bgcolor="#E2E8EB" style="font-size:14px;height:25px;font-weight:bold">
        <td width="35px">编号</td>
		<td width="85px">图片</td>
		<td width="420px">商品名称</td>
		<td>数量</td>
		<td>单价</td>
		<td>小计</td>
		<td>删除</td>
	</tr>
<volist name="cart" id="cart">
<tr align="center" >
   <td>{$i}</td>
   <td align="center"><img src="__APP__/{$cart.s_pic}" height="50"/></td>
   <td  align="left" ><a href="__APP__/Goods/item/?id={$cart.goods_id}">{$cart.name}</a><br><span>{$cart.props}</span></td>

   <td>
			<input id="min" name="min" type="button"  value="-"/>
			<input id="text_box" name="num" type="text" style="text-align:center;width:50px;" value="{$cart.product_num}" readonly/>
			<input id="add" name="add" type="button" value="+" />
			<input name="store" type="text" value="{$cart.store}" style="display:none">
			<input id="p_id" type="text"  value="{$cart.product_id}" style="display:none"/>
	</td>
	<td name="price">{$cart.price}</td>
	<td  bgcolor="#FFFDEE" name="zone" style="color:#FF0000;font-weight:bold">{$cart.s_money}</td>
	<td><a href='javascript:;' onclick="remove({$cart.product_id})"><img src="__APP__/statics/btn-close.gif"/></a></td>

</tr>
</volist>
</table>
</div>
 
 <div class="total">
	 <span>
		 <a href="__APP__"><img src="__APP__/statics/btn-gobuy.gif"></a>
		 <a href="javascript:;"  onclick="catClear()"><img src="__APP__/statics/btn-clearcat.gif"></a>
	 </span>
	 <span id="sum_num" style="float:right;font-size:20px">商品总额：<font color="red"><b>￥{$total_money}</b></font></span>
 </div>
 <br>

</div>
<div class="toorder">
<span><a id="checkorder" href="javascript:;"><img src="__APP__/statics/btn-next.gif" border="0"></a></span>
</div>

<div id="errormsg"></div>
<link rel="stylesheet" type="text/css" href="__APP__/statics/css/jNotify.jquery.css" />

<script type="text/javascript" src="__APP__/statics/jNotify.jquery.js"></script>
<script type="text/javascript">
$(function(){ 
	  

	  $("[name=min]").click(function(){
	     $(this).next().next().attr('disabled',false);
	     var n=$(this).next().val();
		 var price=$(this).parent().next().text();
		 var pid=$(this).next().next().next().next().val();
		 if (parseInt(n)==1){
		    $(this).attr('disabled',true);
		 }else{
		    var num=parseInt(n)-1;
		    $(this).next().val(num);
			var s_money=num*price;
			$(this).parent().next().next().html(s_money.toFixed(2));
            sumPrice();
			$.ajax({type:"GET",dataType:"html",url:"__URL__/up_num",data:{id:pid,num:num}})
		}
	  })

	  $("[name=add]").click(function(){
	       $(this).prev().prev().attr('disabled',false);
	        var store=$(this).next().val();
			var n=$(this).prev().val();
			var price=$(this).parent().next().text();
			var pid=$(this).next().next().val();

			if (parseInt(n)==parseInt(store)){
		        $(this).attr('disabled',true);
		    }else{
		         var num=parseInt(n)+1;
		         $(this).prev().val(num);
			     var s_money=num*price;
			     $(this).parent().next().next().html(s_money.toFixed(2));
			     sumPrice();
                 //更改cookie
				 $.ajax({type:"GET",dataType:"html",url:"__URL__/up_num",data:{id:pid,num:num}})
			}
	  })

	  function sumPrice(){
	      var totalprice=0;
	      $("[name=zone]").each(function(){
		     var s_money=$(this).text();
			 totalprice+=parseFloat(s_money);
		   })
		   $("#sum_num").html("商品总额：<font color='red'><b>￥"+totalprice.toFixed(2)+"</b></font>");
	  }

	  //跳转到结算页面
	  $("#checkorder").click(function(){
	      var totalprice=0;
	      $("[name=zone]").each(function(){
		     var s_money=$(this).text();
			 totalprice+=parseFloat(s_money);
		  })
		  if(totalprice!=0){
	         window.location.href="__GROUP__/Order/check";
		  }else{
		       jError("<strong>您的购物车为空！</strong>",{VerticalPosition : 'center',HorizontalPosition : 'center'});
		  }
	  })

})

function catClear(){
		   if(confirm('你确认要清空购物车吗？')) {
				 $.ajax({
				     type:"GET",
					 url:"__APP__/Cart/clear_cart",
					 success:function(data){
					    jSuccess("<strong>购物车清空成功！</strong>",{VerticalPosition : 'center',HorizontalPosition : 'center',onClosed:function(){location.reload();}});
					 }	
				})
			}
}

//移除
function remove(t){
  if(confirm('你确认要移除此商品吗？')) {
		var product_id=t;
		$.get('__URL__/del',{id:product_id},function(res){
			jSuccess("<strong>移除成功！</strong>",{VerticalPosition : 'center',HorizontalPosition : 'center',onClosed:function(){location.reload();}});
		})
		//ajax结束
		sumPrice();

   }    
}
</script>

<include file="Public:footer" /> 